using System;
using System.Runtime.Serialization;

namespace DependencyAnalysis.DataModel
{
    /// <summary>
    /// Represents an instruction of the intermediate code.
    /// </summary>
    [Serializable]
    [DataContract]
    [KnownType(typeof(MemberDescriptor))]
    [KnownType(typeof(TypeDescriptor))]
    [KnownType(typeof(ModuleDescriptor))]
    public class Instruction
    {
        [NonSerialized]
        private object _operandNonSerialized;

        /// <summary>
        /// Position in number of bytes
        /// </summary>
        [DataMember(Order = 1)]
        public long Offset { get; set; }

        /// <summary>
        /// the type of the operand depends on the OpCode
        /// </summary>
        public object OperandNonSerialized
        {
            get { return _operandNonSerialized; }
            set { _operandNonSerialized = value; }
        }

        /// <summary>
        /// the type of the operand depends on the OpCode
        /// </summary>
        [DataMember(Order = 2)]
        public object Operand { get; set; }

        /// <summary>
        /// Specifies the operation to be performed
        /// </summary>
        [DataMember(Order = 3)]
        public OperationCode OpCode { get; set; }
    }
}